package com.lt.contract.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.lt.contract.bean.utils.ExcelUtil;
import com.lt.contract.entity.NmOneStopService;
import com.lt.contract.entity.TfFBigcustUserAll;
import com.lt.contract.entity.ZqSgjs;
import com.lt.contract.service.TfFBigcustUserAllService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * (TfFBigcustUserAll)表控制层
 *
 * @author makejava
 * @since 2020-03-28 16:17:09
 */
@RestController
@RequestMapping("tfFBigcustUserAll")
@Slf4j
public class TfFBigcustUserAllController {
    /**
     * 服务对象
     */
    @Resource
    private TfFBigcustUserAllService tfFBigcustUserAllService;

    @Resource
    NmRoleController controller;

    /**
     * 获取  系统收入
     * @param params
     * @return
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/queryAll")
    public JSONArray queryAll(@RequestParam String params){
        System.out.println(params);
        List<TfFBigcustUserAll> contractList = null;
        try {
            params =  controller.getRole(params);
            Map<String,Object> map = JSON.parseObject(params);
            contractList = tfFBigcustUserAllService.queryAll(map);
            JSONArray result = JSON.parseArray(JSON.toJSONString(contractList));
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    /**
     * 获取  系统收入
     * @param params
     * @return
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/queryAllCount")
    public Long queryAllCount(@RequestParam String params){
        try {
            params =  controller.getRole(params);
            Map<String,Object> map = JSON.parseObject(params);
            Long count = tfFBigcustUserAllService.queryCount(map);
            return count;
        }catch (Exception e){
            e.printStackTrace();
            return 0L;
        }

    }

    @GetMapping(value = "/download")
    @CrossOrigin
    public void exportList(@RequestParam String params, HttpServletResponse response) {
        log.info("zqSgjs download");
        try {
            params =  controller.getRole(params);
            Map<String,Object> map = JSON.parseObject(params);
            List<TfFBigcustUserAll> nmCirciuitRealations = tfFBigcustUserAllService.exportList(map);
            String fileName = "系统计收明细"+System.currentTimeMillis() + ".xlsx";
            ExcelUtil.writeExcel(response,nmCirciuitRealations,fileName,"系统计收明细",new TfFBigcustUserAll());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
